package com.taokatao.cardmee.business.cardcode;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.taokatao.cardmee.R;
import com.taokatao.cardmee.db.model.Card;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CardCodeIBackLayout extends ICardDetailInfoLayout {

    @BindView(R.id.i_picture) ImageView iPicture;

    public CardCodeIBackLayout(Context context) {
        this(context, null);
    }

    public CardCodeIBackLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        ButterKnife.bind(LayoutInflater.from(context).inflate(R.layout.layout_card_code_picture, this));
    }

    @Override
    void prepareData(final Card c) {
        iPicture.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(v.getContext(), CardCodePictureActivity.class);
                intent.putExtra("extra_card", c);
                intent.putExtra("extra_select_item", c.getBackIcon());
                v.getContext().startActivity(intent);
            }
        });

        if (!TextUtils.isEmpty(c.getBackIcon())) {
            Glide.with(getContext()).load(c.getBackIcon()).placeholder(R.mipmap.image_holder).into(iPicture);
        }
    }
}
